<?php

use Illuminate\Support\Facades\Route;





Route::group(
    ['prefix' => 'customer/{customer}', 'middleware' => ['customer', 'logs:customer'], 'namespace' => 'App\Http\Controllers\Customer'],
    function () {

        Route::group(
            ['prefix' => 'common', 'middleware' => ['customer', 'auth:customer'], 'namespace' => 'Common'],
            function () {
                Route::post('index/upload', 'IndexController@upload')->name('common.upload');
                Route::get('download/hs_code', 'DownloadController@hsCode')->name('download.hs_code');
            });

        Route::group(
            ['prefix' => 'warehouse', 'middleware' => ['customer', 'auth:customer'], 'namespace' => 'Warehouse'],
            function () {
                Route::put('receiving/{id}/confirm', 'ReceivingController@confirm')->name('receiving.confirm');
                Route::resource('receiving', 'ReceivingController');
            });
        // 产品
        Route::group(
            ['prefix' => 'product', 'middleware' => ['customer', 'rbac:customer', 'logs:customer'], 'namespace' => 'Product'],
            function () {
                Route::get('select', 'IndexController@select');

                Route::resource('index','IndexController')
                    ->name('create', 'product.store')
                    ->name('edit', 'product.update')
                    ->name('index', 'product.index')
                    ->name('store', 'product.store')
                    ->name('show', 'product.show')
                    ->name('update', 'product.update');

                Route::resource('import','ImportController')
                    ->name('index', 'import.index')
                    ->name('store', 'import.store')
                    ->except(['show', 'edit', 'create', 'update', 'destroy']);

                Route::resource('distribution','DistributionController')
                    ->name('index', 'distribution.index')
                    ->name('store', 'distribution.store')
                    ->except(['show', 'edit', 'create', 'update', 'destroy']);
            });


        // 不登录也可以进入
        Route::group(
            ['middleware' => ['guest:customer', 'customer']],
            function () {
                Route::post('login', 'AuthController@login');
                Route::put('refresh', 'AuthController@refresh');
            }
        );
        // 登录才可以进入
        Route::group(
            ['middleware' => ['auth:customer', 'customer']],
            function () {
                Route::delete('logout', 'AuthController@logout');
                Route::get('profile/logs', 'AuthController@logs');
                Route::get('profile', 'AuthController@profile');
                Route::put('profile/password', 'AuthController@password');
            }
        );

        // 要验证权限
        Route::group(
            ['middleware' => ['rbac:customer', 'auth:customer'], 'prefix' => 'authorities'],
            function () {
                Route::get('menu/authority', 'Authorities\MenuController@authority')->name('role.menu_authority');
                Route::resource('role','Authorities\RoleController')
                    ->name('edit', 'role.update')
                    ->name('create', 'role.store')
                    ->except(['show']);

                Route::put('user/{user}/status', 'Authorities\UserController@status')->name('user.update');
                Route::resource('user','Authorities\UserController')
                    ->name('edit', 'user.update')
                    ->name('create', 'user.store')
                    ->except(['show', 'destroy']);
            }
        );
    }
);
